package com.flyox.game.militarychess.test;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

public class BackgroundSample extends JFrame {
	/**
	 * 
	 */
	private static final long serialVersionUID = 4058381045892143994L;
	JScrollPane scrollPane;
	ImageIcon icon;
	Image image;

	public BackgroundSample() {
		icon = new ImageIcon("C:\\temp\\20071022111936734.jpg");

		JPanel panel = new JPanel() {
			/**
			 * 
			 */
			private static final long serialVersionUID = 4850481805271426393L;

			protected void paintComponent(Graphics g) {
				super.paintComponent(g);
			    Graphics2D g2d = (Graphics2D) g;
			    
				// Dispaly image at at full size
			    g2d.drawImage(icon.getImage(), 0, 0, null);
				// Scale image to size of component
				// Dimension d = getSize();
				// g.drawImage(icon.getImage(), 0, 0, d.width, d.height, null);
				// Fix the image position in the scroll pane
				// Point p = scrollPane.getViewport().getViewPosition();
				// g.drawImage(icon.getImage(), p.x, p.y, null);
				//super.paintComponent(g);
			}
		};
		panel.setOpaque(false);
		panel.setPreferredSize(new Dimension(400, 400));
		scrollPane = new JScrollPane(panel);
		getContentPane().add(scrollPane);

		JButton button = new JButton("Hello");
		panel.add(button);
		button.removeAll();
	}

	public static void main(String[] args) {
		BackgroundSample frame = new BackgroundSample();
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setSize(300, 300);
		frame.setLocationRelativeTo(null);
		frame.setVisible(true);
	}
}